package com.stars.system.fitness.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.stars.system.fitness.domain.FitnessBasic;
import com.stars.system.fitness.service.IFitnessBasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 我的习惯Controller
 * 
 * @author shuaibizhe
 * @date 2022-09-09
 */
@RestController
@RequestMapping("/fitness/basic")
public class FitnessBasicController extends BaseController
{
    @Autowired
    private IFitnessBasicService fitnessBasicService;

    /**
     * 查询我的习惯列表
     */
    @PreAuthorize("@ss.hasPermi('fitness:basic:list')")
    @GetMapping("/list")
    public TableDataInfo list(FitnessBasic fitnessBasic)
    {
        startPage();
        List<FitnessBasic> list = fitnessBasicService.selectFitnessBasicList(fitnessBasic);
        return getDataTable(list);
    }

    /**
     * 导出我的习惯列表
     */
    @PreAuthorize("@ss.hasPermi('fitness:basic:export')")
    @Log(title = "我的习惯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FitnessBasic fitnessBasic)
    {
        List<FitnessBasic> list = fitnessBasicService.selectFitnessBasicList(fitnessBasic);
        ExcelUtil<FitnessBasic> util = new ExcelUtil<FitnessBasic>(FitnessBasic.class);
        util.exportExcel(response, list, "我的习惯数据");
    }

    /**
     * 获取我的习惯详细信息
     */
    @PreAuthorize("@ss.hasPermi('fitness:basic:query')")
    @GetMapping(value = "/{basicId}")
    public AjaxResult getInfo(@PathVariable("basicId") String basicId)
    {
        return AjaxResult.success(fitnessBasicService.selectFitnessBasicByBasicId(basicId));
    }

    /**
     * 新增我的习惯
     */
    @PreAuthorize("@ss.hasPermi('fitness:basic:add')")
    @Log(title = "我的习惯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FitnessBasic fitnessBasic)
    {
        return toAjax(fitnessBasicService.insertFitnessBasic(fitnessBasic));
    }

    /**
     * 修改我的习惯
     */
    @PreAuthorize("@ss.hasPermi('fitness:basic:edit')")
    @Log(title = "我的习惯", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FitnessBasic fitnessBasic)
    {
        return toAjax(fitnessBasicService.updateFitnessBasic(fitnessBasic));
    }

    /**
     * 删除我的习惯
     */
    @PreAuthorize("@ss.hasPermi('fitness:basic:remove')")
    @Log(title = "我的习惯", businessType = BusinessType.DELETE)
	@DeleteMapping("/{basicIds}")
    public AjaxResult remove(@PathVariable String[] basicIds)
    {
        return toAjax(fitnessBasicService.deleteFitnessBasicByBasicIds(basicIds));
    }

    /**
     * 查询我的习惯字典值
     */
    @PreAuthorize("@ss.hasPermi('fitness:basic:add')")
    @GetMapping("/dict")
    public Map<String, Object> dict()
    {
        return fitnessBasicService.selectFitnessBasicDict();
    }

    /**
     * 查询我的健身树形结构数据
     */
    @PreAuthorize("@ss.hasPermi('fitness:basic:add')")
    @GetMapping("/tree")
    public List tree()
    {
        return fitnessBasicService.selectFitnessBasicTree();
    }

    /**
     * 导入默认习惯
     */
    @PreAuthorize("@ss.hasPermi('fitness:basic:add')")
    @GetMapping("/import")
    public AjaxResult importBasic()
    {
        return toAjax(fitnessBasicService.importFitnessBasic());
    }
}
